﻿using System.Collections.Generic;
using System.Linq;
using Apps.Web.Core;
using Apps.Locale;
using System.Web.Mvc;
using Apps.Common;
using Apps.IBLL;
using Microsoft.Practices.Unity;
using Newtonsoft.Json.Linq;
using Newtonsoft.Json;
using System;
using System.Data;
using Apps.Models;
using Wantn.FIS.Enum;
using Microsoft.Practices.Unity;
using Apps.Web.Core;
using System.Configuration;
using Microsoft.Ajax.Utilities;

namespace Apps.Web.Areas.RC.Controllers
{
    public class SELF_SAMPLINGController : BaseController
    {
        [SupportFilter]
        public ActionResult Index()
        {
            return View();
        }
        [HttpPost]
        [SupportFilter(ActionName = "Index")]
        public JsonResult GetList(GridPager pager, string queryStr = "", string typeId = "", string RFID = "")
        {
            try
            {
                using (DBContainer db = new DBContainer())
                {
                    string strConnDB = ConfigurationManager.ConnectionStrings["OracleDbContext"].ToString();
                    string sql = "select * from V_SELF_SAMPLING where BATCH_CODE like '%" + queryStr + "%'";
                    if (!string.IsNullOrEmpty(typeId))
                    {
                        sql += " AND TYPE_STR like '%" + typeId + "%'";
                    }
                    if (!string.IsNullOrEmpty(RFID))
                    {
                        sql += " AND RFID like '%" + RFID + "%'";
                    }
                    DataTable _dt = new DataTable();
                    Oracle.ManagedDataAccess.Client.OracleDataAdapter _orcDA = new Oracle.ManagedDataAccess.Client.OracleDataAdapter(sql, strConnDB);
                    _orcDA.Fill(_dt);

                    List<V_SELF_SAMPLING> list = ValueConvert.ToDataList<V_SELF_SAMPLING>(_dt);
                    pager.totalRows = list.Count();
                    ////排序
                    list = LinqHelper.SortingAndPaging(list.AsQueryable(), pager.sort, pager.order, pager.page, pager.rows).ToList();
                    GridRows<V_SELF_SAMPLING> grs = new GridRows<V_SELF_SAMPLING>();
                    grs.rows = list;
                    grs.total = pager.totalRows;
                    return Json(grs);
                }
            }
            catch (Exception ex)
            {
                return Json(JsonHandler.CreateMessage(1, Resource.CheckSucceed));
            }
        }
    }
}